$( document ).on( "pageshow", "#workConList", function( event ) {
	pageNo= isNullOrEmpty(pageNo)? "1" : pageNo;
	pageSize= "10";
	$("#wrapper_workConList  #pullDown").hide();
	$("#wrapper_workConList  #pullUp").hide();
	
	var scrollObj_workConList=scrollPlugLoadedOfReturn_new("wrapper_workConList",
			function() {
				setTimeout(function () {
					if(pageNo >= totalPage){
						$("#wrapper_workConList  #pullUp").hide();
						return;
					}
					pageNo++;
					loadData_workConList(false,scrollObj_workConList);
				}, 1000);	
			},
			function() {
				setTimeout(function () {
					if(pageNo>1){
						pageNo--;
						loadData_workConList(true,scrollObj_workConList);
						if(pageNo==1){
							$("#wrapper_workConList  #pullDown").hide();
						}
					}else{
						$("#wrapper_workConList  #pullDown").hide();
					}
				}, 1000);
			});
	
	loadData_workConList(true,scrollObj_workConList);
	
	
});
$( document ).on( "pagecreate", "#workConList", function( event ) {
	access_token=getParameterByName("access_token", getLocationUrl(event) );
	thisWorkConType = getParameterByName("workConType", getLocationUrl(event) );
	pageNo =getParameterByName("pageNo", getLocationUrl(event) );
	userPostId = getParameterByName("userPostId", getLocationUrl(event) );
	all_e=event;
	if(thisWorkConType == 3){
		workConType = '1';
	}else{
		workConType = thisWorkConType;
	}
	
	//是否显示 我的审阅 按钮 
//	isShowReviewBtn();
	
	//去录入
	$("#goWorkCon").on('click', function () {
		goTo2(rootPath+"/jsp/weixin/workCon.jsp?access_token="+access_token+"&workConType="+thisWorkConType+"&pageNo="+pageNo+"&userPostId="+userPostId,false);
	});
	
	//去 我的审阅
	if(!isNullOrEmpty(thisWorkConType)){
		if(thisWorkConType=="1"||thisWorkConType=="4"){
			$("#workConList_myReview").on('click', function () {
				goTo2(rootPath+"/jsp/weixin/workConViewSList.jsp?access_token="+access_token+"&workConType="+thisWorkConType+"&userPostId="+userPostId,false);
			});
		}else{
			$("#workConList_myReview").on('click', function () {
				goTo2(rootPath+"/jsp/weixin/workConViewList.jsp?access_token="+access_token+"&workConType="+thisWorkConType+"&userPostId="+userPostId,false);
			});
		}
	}else{
		$("#workConList_myReview").on('click', function () {
			goTo2(rootPath+"/jsp/weixin/workConList.jsp?access_token="+access_token+"&workConType="+thisWorkConType+"&userPostId="+userPostId,false);
		});
	}
	
//	if(!isNullOrEmpty(thisWorkConType) && thisWorkConType=="4"&&userPostId=="B"){
//		$("#workConList_myReview").hide();
//	}
	if( !isNullOrEmpty(workConType) && workConType=="2"){
		//去 日志分享
		$("#workConList_shareBtn").show().on('click', function () {
			goTo2(rootPath+"/jsp/weixin/workConShareList.jsp?access_token="+access_token+"&workConType="+workConType+"&userPostId="+userPostId,false);
		});
		//去 特别关注
		$("#workConList_careBtn").show().on('click', function () {
			goTo2(rootPath+"/jsp/weixin/workConCareList.jsp?access_token="+access_token+"&workConType="+workConType+"&userPostId="+userPostId,false);
		});
	}
});
/**
 * 
 * @param isFresh 是否刷新
 * @param isFresh 是否初始列表
 */
function loadData_workConList(isFresh,scrollObj_workConList){
	showLoading();
	$.ajax({
	  	url: rootPath+"/workCon/workConList.do",
	  	type: "POST",
	  	dataType: "text",
		data: "access_token="+access_token+"&workConType="+workConType+"&pageNo="+pageNo+"&pageSize="+pageSize,
	  	success: function( response ) {
	  		hideLoading();
	  		var data=$.parseJSON(response);
			if(data.state=="200"){
				totalPage=data.data.totalPage;
		  		var totalRow=data.data.totalRow;
		  		var arr=data.data.rows;
				var content = "";
				var sideStyle1="style=\'right:5px; \'";
				margin_top_6="style='margin-top:6px;width: 80%; display: inline-block;' ";
				for (var i=0;i<arr.length;i++){
					var toPage=rootPath+"/jsp/weixin/workConInfo.jsp?toWorkConId="+arr[i].id+"&access_token="+access_token+"&workConType="+thisWorkConType+"&isReview=false"+"&pageNo="+pageNo+"&userPostId="+userPostId;//去日志查看页
					var headerPic=rootPath+defaultHeadPic;
					if(arr[i].headImageUrl!=undefined && arr[i].headImageUrl!="" )
						headerPic=arr[i].headImageUrl;
					var name=arr[i].empName;
					var bg_color="c_blue";
					var posiName=arr[i].posiName;
					var reviewState="待审阅";
					if(arr[i].reviewState == "2"){//已审阅 //  <img  '+imgStyle+' src="'+headerPic+'" class="ui-li-icon">
						bg_color="c_yellow";
						reviewState="已审阅";
					}
					//add by jianghaibo 2015-05-22 
					if(arr[i].reviewState == "3"){ //已批注
						bg_color="c_red";
						reviewState="已批示";
					}
					var str =arr[i].log_date; 
					if(isNullOrEmpty(str)) str="";
					if(str!=""){ str = str.replace(/-/g,"/"); var date = new Date(str );var month=date.getMonth()+1;var day=date.getDate();str=month+"月"+day+"日：";}
					var orgName='<span style="font-size:12px;">('+arr[i].orgName+')</span>';
					if( !isNullOrEmpty(workConType) && workConType=="2"){
						content +='<li data-icon="false">\
							  <a href="#"  onClick="goTo2(\''+toPage+'\',false)"  >\
								<p '+margin_top_no+'><span style="font-size:15px;">'+name+orgName+'</span><strong class="ui-li-aside_fresh" '+sideStyle1+' >'+arr[i].create_time+'</strong></p>\
								<p '+margin_top_6+' name=\'whiteSpace'+pageNo+'\'><span style="width:80%">'+str+arr[i].workcon1+'</span><span class="reviewFlag '+bg_color+' " >'+posiName+'</span></p>\
							  </a>\
							</li>';
					}else {
						content +='<li data-icon="false">\
						  <a href="#"  onClick="goTo2(\''+toPage+'\',false)"  >\
							<p '+margin_top_no+'><span style="font-size:15px;">'+name+orgName+'</span><strong class="ui-li-aside_fresh" '+sideStyle1+' >'+arr[i].create_time+'</strong></p>\
							<p '+margin_top_6+' name=\'whiteSpace'+pageNo+'\'><span style="width:80%">'+str+arr[i].workcon1+'</span><span class="reviewFlag '+bg_color+' " >'+reviewState+'</span></p>\
						  </a>\
						</li>';
					}
				}
				if(arr.length<pageSize){
					$("#wrapper_workConList  #pullUp").hide();
				}else{
					$("#wrapper_workConList  #pullUp").show();
				}
				if(isFresh)
					$("#thelist_workConList").html("");
				
				//页数是2的倍数时，清空缓存列表
				if(pageNo%3==0){
					$("#wrapper_workConList  #pullDown").show();
					$("#thelist_workConList").html("");
					$("#thelist_workConList").append(content).listview('refresh');
				}else{
					$("#thelist_workConList").append(content).listview('refresh');
				}
				scrollObj_workConList.refresh();
//				$("[name='whiteSpace"+pageNo+"']").on("tap",function (){
//					p_show(this);
//				});
			}else{
				alert_wx('fail',data.msg);
			}
	  	}
	});
}
/**
 * 是否显示查看他人工作日志的按钮
 */
function isShowReviewBtn(){
	showLoading();
	$.ajax({
	  	url: rootPath+"/workCon/isCanViewOthers.do",
	  	type: "POST",
	  	dataType: "text",
		data: "access_token="+access_token+"&workConType="+workConType,
	  	success: function( response ) {
	  		hideLoading();
	  		var data=$.parseJSON(response);
			if(data.state=="200"){
				$("#workConList_myReview").show();
			}else{
				$("#workConList_myReview").hide();
			}
	  	}
	});
}
			